﻿using Avalonia.BiliBili.Libs.Models.View;
using Bilibili.Common.Log;
using Bilibili.Model.Common;
using Bilibili.Model.Rank;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace Avalonia.BiliBili.ViewModels
{
    public sealed class RankViewModel : ViewModelBase
    {
        private ObservableCollection<TabControlItem<RankItemModel>> items = [];
        public ObservableCollection<TabControlItem<RankItemModel>> Items
        {
            get => items;
            private set => this.RaiseAndSetIfChanged(ref items, value);
        }
        public int Current { get; set; } = 0;
        public List<Category> Categories { get; }
        public RankViewModel()
        {
            Categories =
            [
                new Category(0, "全站", RankRegion.All),
                new Category(0, "原创", RankRegion.Origin),
                new Category(0, "新人", RankRegion.Rookie),
                new Category(1, "动画", RankRegion.All),
                new Category(168, "国创", RankRegion.All),
                new Category(3, "音乐", RankRegion.All),
                new Category(129, "舞蹈", RankRegion.All),
                new Category(4, "游戏", RankRegion.All),
                new Category(36, "知识", RankRegion.All),
                new Category(188, "数码", RankRegion.All),
                new Category(160, "生活", RankRegion.All),
                new Category(211, "美食", RankRegion.All),
                new Category(119, "鬼畜", RankRegion.All),
                new Category(155, "时尚", RankRegion.All),
                new Category(5, "娱乐", RankRegion.All),
                new Category(181, "影视", RankRegion.All)
            ];
        }
        public void InitCategory()
        {
            try
            {
                for (var idx = 0; idx < Categories.Count; idx++)
                {
                    var category = Categories.ElementAt(idx);
                    Items.Add(new TabControlItem<RankItemModel>(category.Content, idx));
                }
            }
            catch (Exception ex)
            {
                LogManager.Instance.LogError("InitCategory", ex);
            }
        }
    }
}